package com.example.rabbitdemo;


import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class RmService extends Service {
    Thread thread;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            // 获取RabbitMQ的消息数据
            String messageData = msg.getData().getString("msg");
            Toast.makeText(RmService.this, messageData, Toast.LENGTH_SHORT).show();
            Log.i("rabbitMQ", messageData);
            Dialogshow(messageData);
        }
    };




    @Override
    public void onCreate() {
        thread=RabbitMqUtils.subscribe(handler);
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        RabbitMqUtils.closeCoon(thread);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        return super.onStartCommand(intent, flags, startId);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    private void Dialogshow(String messageData) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(AppManager.getAppManager().currentActivity());
        alertDialogBuilder.setTitle("警报！！！").setMessage(messageData).show();
    }
}
